package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.impl.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> selectPage(@ApiParam(value = "护理项目名称") String name,
                                                               @ApiParam(value = "当前页") @RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                                               @ApiParam(value = "每页显示记录数") @RequestParam(defaultValue = "10", required = false) Integer pageSize,
                                                               @ApiParam(value = "状态")Integer status){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, status, pageNum, pageSize);

        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id){
        NursingProjectVo vo = nursingProjectService.getById(id);

        return success(vo);
    }

    @PutMapping
    @ApiOperation("根据id更新数据")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);

        return success();
    }
}
